﻿using System;
using System.Collections.Generic;
using Demo.Business;
using Demo.Presentation;
using MvpFramework;

namespace DemoWeb
{
    public partial class _Default : MvpPage,IEditPersonView
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            AllPeopleControl.SelectedIndexChanged += (o, ev) => PersonSelected(o, ev);
            AddNewButton.Click += (o, ev) => PersonAdded(o, ev);
            SaveExistingButton.Click += (o, ev) => PersonSaved(o, ev);
        }
        public IEnumerable<Person> AllPeople
        {
            set 
            { 
                AllPeopleControl.DataSource = value;
                AllPeopleControl.DataBind();
            }
        }

        public Guid SelectedPersonId
        {
            get
            {
                return AllPeopleControl.Items.Count > 0
                           ?
                               new Guid(AllPeopleControl.SelectedValue)
                           : Guid.Empty; 
            }
        }

        public event EventHandler PersonSelected = delegate { };
        public event EventHandler PersonSaved = delegate { };
        public event EventHandler PersonAdded = delegate { };
        public string Name
        {
            get { return NameControl.Text; }
            set { NameControl.Text = value; }
        }
    }
}
